/**
 * 
 */
package com.feonix.designPattern.composite.sample;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @CopyRight (c)1993-2017
 * @Project common_practice
 * @Comments 请输入该类的描述
 * @NameSpace com.feonix.designPattern.composite.sample
 * @Author Feonixzw
 * @CreateDate 2018年2月6日
 */
public class Directory extends Entry {

	private String name;

	private List directory = new ArrayList();

	/**
	 * 
	 */
	public Directory(String name) {
		this.name = name;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return this.name;
	}

	@Override
	public int getSize() {
		int size = 0;
		Iterator iterator = directory.iterator();
		while (iterator.hasNext()) {
			Entry entry = (Entry) iterator.next();
			size += entry.getSize();
		}
		return size;
	}

	@Override
	protected void printList(String prefix) {
		System.out.println(prefix + "/" + this.toString());
		Iterator iterator = directory.iterator();
		while (iterator.hasNext()) {
			Entry entry = (Entry) iterator.next();
			entry.printList(prefix + "/" + this.name);
		}
	}

	@Override
	public Entry add(Entry entry) {
		directory.add(entry);
		return this;
	}

}
